*     *****************************************************************   *;
*     *****************************************************************   *; 
*   Date:          December 27, 2021                               	      *;
*   Authors:       Lisa Dellmuth and Jonas Tallberg				          *;   
*   Purpose: 	   Analyses for book Legitimacy Politics: Elite  		  *;
*    Communication and Public Opinion in Global Governance (CUP, 2023)    *;
*     ****************************************************************    *;
*     ****************************************************************    *;


*     ****************************************************************  *;
*     Appendix : Results with interaction terms				       	    *;
*     ****************************************************************  *;
 

use Elitecom.dta, clear

*Replicate Table D1
set more off

gen partyid=0
*DE: CDU/CSU/SPD
*UK: Tory/Liberal
*US: Democrats
tab partyID_neu, nol
replace partyid=1 if partyID_neu==1|partyID_neu==2
tab qpartyid, nol
replace partyid=1 if qpartyid==2|qpartyid==3
tab pid3, nol
replace partyid=1 if pid3==1
by country, sort: tab partyid


***This is figure 4.4:
*************************************
gen t_gov_nxpartyid=t_gov_n*partyid
reg conf t_gov_n partyid t_gov_nxpartyid  [aw=weight],  cluster(id) 

matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1] 
scalar b2=b[1,2]
scalar b3=b[1,3]
scalar b4=b[1,4]
scalar b5=b[1,5]
scalar b6=b[1,6] 

scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]
scalar varb4=V[4,4]
scalar varb5=V[5,5]
scalar varb6=V[6,6] 

scalar covb1b3=V[1,3] 
scalar covb2b3=V[2,3] 

scalar list b1 b2 b3 b4 b5 b6  varb1 varb2 varb3 varb4 varb5 varb6 covb1b3 covb2b3

gen conb0=b1                                   /* Marginal Effect if Z==0 */
gen conb1=b1+b3*1                              /* Marginal Effect if Z==1 */

gen conse0=sqrt(varb1+varb3*(0^2)+2*covb1b3*0)   /* if Z==0 */
gen conse1=sqrt(varb1+varb3*(1^2)+2*covb1b3*1)   /* if Z==1 */

gen upper0=conb0+1.96*conse0
gen lower0=conb0-1.96*conse0

gen upper1=conb1+1.96*conse1
gen lower1=conb1-1.96*conse1

gen upper = upper0     if partyid==0
replace upper = upper1 if partyid==1

gen lower = lower0     if partyid==0
replace lower = lower1 if partyid==1

gen con = conb0        if partyid==0
replace con = conb1    if partyid==1

set plotplain
#delimit ;
eclplot con lower upper partyid, 
estopts(msize(large)) ciopts(msize(large))
xlab(0 1) xtitle("Partisan identification with party in government", size(4))
ytitle("ATE of negative government communication", size(4))			
xscale(range(-1 2)) yline(0, lcolor(black) lpattern(dash))
scheme(lean2) ylabel(, nogrid) legend(position(6));
;
#delimit cr

